<template>
  <!-- 新增盘点方案 -->
  <div class="stock">
    <div class="dropdown">
      <el-button type="primary" size="mini" @click.native="subMarker">{{ $t('btn.save') }}</el-button>
    </div>
    <el-tabs v-model="activeName">
      <el-tab-pane :label="$t('market.info')" name="first">
        <el-form ref="purchaseRef" :model="prodValue" label-width="100px">
          <el-form-item :label="$t('market.billType')" prop="fpaezCombo">
            <el-select v-model="prodValue.fbillTypeId" size="mini" filterable>
              <el-option
                v-for="(item, index) in billtypes"
                :key="index"
                :label="item.fname"
                :value="item.fid"
              />
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('market.inventPlanName')">
            <el-input v-model="prodValue.fname" size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.inventPlanfbi')">
            <el-input v-model="prodValue.fbillno" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.note')">
            <el-input v-model="prodValue.fnote" size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.inventPlanper')">
            <el-radio v-model="prodValue.forthwithRep" label="1">{{ $t('market.forthwithRep') }}</el-radio>
            <el-radio v-model="prodValue.forthwithRep" label="2">{{ $t('market.lingCheck') }}</el-radio>
            <!--            <el-checkbox v-model="prodValue.fzerostockincount">{{ $t('market.lingCheck') }}</el-checkbox>-->
          </el-form-item>
          <el-form-item :label="$t('market.countqty')">
            <el-checkbox v-model="prodValue.defaultstatus">默认即时库存</el-checkbox>
          </el-form-item>
          <el-form-item :label="$t('market.inventdefau')">
            <el-input-number v-model="prodValue.fcheckqtydefault" size="mini" controls-position="right" />
          </el-form-item>
          <el-form-item :label="$t('market.stockNumber')">
            <el-input v-model="prodValue.fstockname" size="mini">
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="seleceVisiblit=true"
              />
            </el-input>
          </el-form-item>
          <el-form-item :label="$t('market.stockplace')">
            <el-input v-model="prodValue.fpositionname" size="mini">
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="shipVisiblit=true"
              />
            </el-input>
          </el-form-item>
        </el-form>
      </el-tab-pane>
    </el-tabs>
    <!--仓库-->
    <el-dialog
      v-dialogDrag
      :title="$t('menu.stockList')"
      modal
      :close-on-click-modal="false"
      :visible.sync="seleceVisiblit"
    >
      <selectWms :msg="1" @client="selectData" />
    </el-dialog>
    <!--仓位-->
    <el-dialog
      v-dialogDrag
      :title="$t('menu.shipSpace')"
      modal
      :close-on-click-modal="false"
      :visible.sync="shipVisiblit"
    >
      <shipSpace :msg="1" @client="shipData" />
    </el-dialog>
  </div>
</template>

<script>
import {
  insertStkcountscheme
} from '@/api/wms/stock'
import { queryViewItem } from '@/api/marketManage/marketOrder'

export default {
  components: {
    selectWms: () => import('@/views/wms/stockWms'),
    shipSpace: () => import('@/views/wms/shipSpace')
  },
  data() {
    return {
      shipVisiblit: false,
      seleceVisiblit: false,
      activeName: 'first',
      billtypes: [], // 类型
      prodValue: {
        defaultstatus: true,
        fdocumentstatus: 'A',
        fbillTypeId: 1513,
        fbillno: '',
        fname: '',
        fnote: '',
        forthwithRep: '1',
        fcheckqtydefault: 0,
        fzerostockincount: '',
        fid: '',
        fstockname: '',
        fpositionname: ''
      },
      fstockArr: [],
      fshipArr: []
    }
  },
  created() {
    this.queryTBasBilltype()
  },
  methods: {
    // 保存
    subMarker() {
      const DATA = {
        ...this.prodValue,
        defaultstatus: this.prodValue.defaultstatus ? 1 : 0,
        fzerostockincount: this.prodValue.fzerostockincount ? '1' : '0'
      }
      insertStkcountscheme(DATA).then(res => {
        if (res.code === 0) {
          // 关闭当前页面
          this.$store.dispatch('tagsView/guanbi', this.$route)
          this.$router.push({ path: `/inventoryWmsDetail/${res.data.fid}` })
          this.$message({ showClose: true, message: res.message, type: 'success' })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            type: 'warning'
          })
        }
      })
    },
    // 查询单据类型
    async queryTBasBilltype() {
      const { data: RES } = await queryViewItem({ viewName: 'SX_WMS_STKCOUNTSCHEME' })
      this.billtypes = RES.list
    },
    // 选择仓库
    selectData(ev) {
      if (ev.fid) {
        this.fstockArr.push(ev.fid)
        this.prodValue.fstockidStr = this.fstockArr
        this.prodValue.fstockname += ev.fname + ','
      }
      this.seleceVisiblit = false
    },
    // 选择仓位
    shipData(ev) {
      if (ev.fid) {
        this.fshipArr.push(ev.fid)
        this.prodValue.fpositionidStr = this.fshipArr
        this.prodValue.fpositionname += ev.fname + ','
      }
      this.shipVisiblit = false
    }
  }
}
</script>

<style scoped lang="scss">
.stock {
  padding: 10px;
  background: #fff;
  min-height: calc(100vh - 100px);
  .el-input::v-deep .el-input__inner {
    height: 30px;
    line-height: 30px;
  }
  .el-form {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;

    .el-form-item {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      height: 35px;
      width: 350px;
      margin-bottom: 5px;
      .btnType {
        margin-right: 20px;
      }

      .el-date-editor.el-input {
        width: 100% !important;
      }

      .el-select {
        width: 100%;
      }
    }
  }
}
</style>
